package demo6;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class PlayWritable implements WritableComparable<PlayWritable> {

    private int viewer;
    private int length;

    public PlayWritable() {
    }

    public PlayWritable(int viewer, int length) {
        this.viewer = viewer;
        this.length = length;
    }

    public int getViewer() {
        return viewer;
    }

    public void setViewer(int viewer) {
        this.viewer = viewer;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    @Override
    public int compareTo(PlayWritable o) {
        if (this.viewer != o.viewer){
            return this.viewer - o.viewer;
        }
        return this.length - o.length;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(viewer);
        out.writeInt(length);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        viewer = in.readInt();
        length = in.readInt();
    }

    @Override
    public String toString() {
        return viewer + "\t" + length;
    }
    /*@Override
    public String toString() {
        return "PlayWritable{" +
                "viewer=" + viewer +
                ", length=" + length +
                '}';
    }*/
}
